package router

import (
	"gitee.com/luleilulei/tk/handlers/comment"
	"gitee.com/luleilulei/tk/handlers/user_info"
	"gitee.com/luleilulei/tk/handlers/user_login"
	"gitee.com/luleilulei/tk/handlers/video"
	"gitee.com/luleilulei/tk/middleware"
	"gitee.com/luleilulei/tk/models"
	"github.com/gin-gonic/gin"
)

func InitDouyinRouter() *gin.Engine {
	models.InitDB()
	// 创建路由
	r := gin.Default()
	// 配置静态文件夹路径 第一个参数是api，第二个是文件夹路径
	r.Static("static", "./static")
	// 抖音客户端接口都有共同的/douyin前缀
	baseGroup := r.Group("/douyin")
	// 基础接口
	baseGroup.GET("/feed/", video.FeedVideoListHandler)                                           // 视频流接口
	baseGroup.POST("/user/register/", middleware.SHAMiddleWare(), user_login.UserRegisterHandler) // 用户注册
	baseGroup.POST("/user/login/", middleware.SHAMiddleWare(), user_login.UserLoginHandler)       // 用户登录
	baseGroup.GET("/user/", middleware.JWTMiddleWare(), user_info.UserInfoHandler)                // 用户信息
	baseGroup.POST("/publish/action/", middleware.JWTMiddleWare(), video.PublishVideoHandler)     // 视频投稿
	baseGroup.GET("/publish/list/", middleware.NoAuthToGetUserId(), video.QueryVideoListHandler)  // 发布列表
	// 互动操作
	baseGroup.POST("/favorite/action/", middleware.JWTMiddleWare(), video.PostFavorHandler)            // 点赞
	baseGroup.GET("/favorite/list/", middleware.NoAuthToGetUserId(), video.QueryFavorVideoListHandler) // 点赞列表
	baseGroup.POST("/comment/action/", middleware.JWTMiddleWare(), comment.PostCommentHandler)         // 评论
	baseGroup.GET("/comment/list/", middleware.JWTMiddleWare(), comment.QueryCommentListHandler)       // 评论列表
	// 社交接口
	baseGroup.POST("/relation/action/", middleware.JWTMiddleWare(), user_info.PostFollowActionHandler)        // 关注
	baseGroup.GET("/relation/follow/list/", middleware.NoAuthToGetUserId(), user_info.QueryFollowListHandler) // 关注用户列表
	baseGroup.GET("/relation/follower/list/", middleware.NoAuthToGetUserId(), user_info.QueryFollowerHandler) // 粉丝列表
	return r
}
